package logic

import (
	"context"
	"errors"
	"home-view/models/mysql"

	"home-view/homerpc/homerpc"
	"home-view/homerpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type CollectDelLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCollectDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CollectDelLogic {
	return &CollectDelLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *CollectDelLogic) CollectDel(in *homerpc.CollectDelRequest) (*homerpc.CollectDelResponse, error) {
	// todo: add your logic here and delete this line

	var collect mysql.Collect

	if err := collect.FindCollectById(mysql.DB, in.CollectId); err != nil {
		return nil, err
	}

	if err := collect.CollectDel(mysql.DB, in.CollectId); err != nil {
		return nil, errors.New("商品失败")
	}

	return &homerpc.CollectDelResponse{}, nil
}
